package com.yzx.lifeassistants.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.bmob.v3.datatype.BmobFile;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.wechat.favorite.WechatFavorite;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

import com.balysv.materialripple.MaterialRippleLayout;
import com.rengwuxian.materialedittext.MaterialEditText;
import com.rengwuxian.materialedittext.validation.METValidator;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.bean.SocializeEntity;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners.SnsPostListener;
import com.umeng.socialize.media.UMImage;
import com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner;
import com.yzx.lifeassistants.R;
import com.yzx.lifeassistants.adapter.ShareListAdapter;
import com.yzx.lifeassistants.adapter.UnEditGridAdapter;
import com.yzx.lifeassistants.base.BaseActivity;
import com.yzx.lifeassistants.bean.FindThing;
import com.yzx.lifeassistants.bean.ImageItem;
import com.yzx.lifeassistants.bean.LostThing;
import com.yzx.lifeassistants.bean.SharePlatform;
import com.yzx.lifeassistants.common.CommonConstant;
import com.yzx.lifeassistants.utils.AppUtils;
import com.yzx.lifeassistants.utils.DensityUtils;
import com.yzx.lifeassistants.utils.FileUtils;
import com.yzx.lifeassistants.utils.LogcatUtils;
import com.yzx.lifeassistants.utils.ScreenUtils;
import com.yzx.lifeassistants.utils.ToastUtils;
import com.yzx.lifeassistants.utils.VerifyUtils;
import com.yzx.lifeassistants.view.widget.NoScrollGridView;

/**
 * @Description: 失物招领
 * @author: yzx
 * @time: 2015-9-15 下午5:14:22
 */
@SuppressLint({ "SimpleDateFormat", "ClickableViewAccessibility",
		"InflateParams" })
public class LostAndFindActivity extends BaseActivity implements
		OnClickListener, OnItemClickListener {
	private String from;//
	private TextView topTitleTV;// 顶部标题
	private ImageButton topBackIB;// 顶部返回按钮
	private ImageButton topShareBtn;// 顶部分享按钮
	private List<ImageView> imgList;//
	private List<LinearLayout> llList;//
	private List<Boolean> isOpenList;//
	private Handler shareHandler;// 分享
	private RelativeLayout topLayout;// 分享界面头部
	private LinearLayout itemLayout;// 分享物品信息
	private LinearLayout otherLayout;// 分享其他信息
	private RelativeLayout itemsRL;// 物品信息
	private LinearLayout itemsLL;// 物品信息
	private RelativeLayout otherRL;// 其他信息
	private LinearLayout otherLL;// 其他信息
	private ImageView itemsImg;// 向上或向下箭头
	private ImageView otherImg;// 向上或向下箭头
	private MaterialEditText titleET;// 物品标题
	private MaterialBetterSpinner typeSp;// 物品类型
	private MaterialEditText describeET;// 物品描述
	private MaterialEditText placeET;// 拾取/丢失地点
	private MaterialEditText timeET;// 拾取/丢失时间
	private MaterialEditText phoneET;// 联系号码
	private List<ImageItem> picList;// 图片列表信息
	private NoScrollGridView picGV;// 图片列表

	private List<BmobFile> picFileList;// 图片文件列表
	private UnEditGridAdapter unEditAdapter;// 图片列表不可编辑的适配器
	// //////////QQ,QZone使用友盟分享,其余使用ShareSDK分享//////////////
	private ShareParams shareParams;// 分享内容
	private PlatformActionListener listener;// 分享回调监听
	private Bitmap bitmap;// 分享图片
	private String shareImagePath;// 分享图片路径
	private UMSocialService mShareController;// 友盟分享控制器
	private SnsPostListener snsPostListener;// 友盟分享回调监听

	private View shareView;// 分享弹框
	private AlertDialog theDialog;// 分享弹框

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lost_find);
		init();
		initView();
		initShareDialog();
		initData();
		initMaterialRipple();
	}

	/**
	 * 
	 * @Description: 初始化上个界面传来的值
	 */
	private void init() {
		from = getIntent().getStringExtra("from");
	}

	/**
	 * 
	 * @Description: 初始化控件
	 */
	private void initView() {
		topLayout = (RelativeLayout) findViewById(R.id.back_head);
		itemsRL = (RelativeLayout) findViewById(R.id.lost_find_items_title_rl);
		itemLayout = (LinearLayout) findViewById(R.id.new_lost_find_items);
		otherLayout = (LinearLayout) findViewById(R.id.new_lost_find_other);
		otherRL = (RelativeLayout) findViewById(R.id.lost_find_other_title_rl);
		itemsLL = (LinearLayout) findViewById(R.id.lost_find_items_ll);
		otherLL = (LinearLayout) findViewById(R.id.lost_find_other_ll);
		itemsImg = (ImageView) findViewById(R.id.lost_find_items_title_arrow_img);
		otherImg = (ImageView) findViewById(R.id.lost_find_other_title_arrow_img);
		topBackIB = (ImageButton) findViewById(R.id.top_back_btn);
		topBackIB.setOnClickListener(this);
		topShareBtn = (ImageButton) findViewById(R.id.top_share_btn);
		topShareBtn.setVisibility(View.VISIBLE);
		topShareBtn.setOnClickListener(this);

		topTitleTV = (TextView) findViewById(R.id.top_title_tv);
		titleET = (MaterialEditText) findViewById(R.id.lost_find_items_title_edit);
		typeSp = (MaterialBetterSpinner) findViewById(R.id.lost_find_items_type_spinner);
		describeET = (MaterialEditText) findViewById(R.id.lost_find_items_describe_edit);
		placeET = (MaterialEditText) findViewById(R.id.lost_find_other_place_edit);
		timeET = (MaterialEditText) findViewById(R.id.lost_find_other_time_edit);
		phoneET = (MaterialEditText) findViewById(R.id.lost_find_other_phone_edit);
		picGV = (NoScrollGridView) findViewById(R.id.lost_find_items_pic_gv);
		picGV.setOnItemClickListener(this);
	}

	/**
	 * 
	 * @Description: 初始化分享框
	 */
	private void initShareDialog() {
		// 弹框
		theDialog = new AlertDialog.Builder(this, R.style.ShareDialog).create();
		theDialog.setCanceledOnTouchOutside(true);
		shareView = LayoutInflater.from(this).inflate(R.layout.dialog_share,
				null);
		List<SharePlatform> shareList = new ArrayList<SharePlatform>();
		shareList.add(new SharePlatform("QQ好友",
				R.drawable.ssdk_oks_skyblue_logo_qq_checked));
		shareList.add(new SharePlatform("QQ空间",
				R.drawable.ssdk_oks_skyblue_logo_qzone_checked));
		shareList.add(new SharePlatform("新浪微博",
				R.drawable.ssdk_oks_skyblue_logo_sinaweibo_checked));
		shareList.add(new SharePlatform("微信好友",
				R.drawable.ssdk_oks_skyblue_logo_wechat_checked));
		shareList.add(new SharePlatform("微信收藏",
				R.drawable.ssdk_oks_skyblue_logo_wechatfavorite_checked));
		shareList.add(new SharePlatform("微信朋友圈",
				R.drawable.ssdk_oks_skyblue_logo_wechatmoments_checked));
		shareList.add(new SharePlatform("更多", R.drawable.ic_share_more));
		ListView shareLV = (ListView) shareView
				.findViewById(R.id.dialog_share_lv);
		ShareListAdapter adapter = new ShareListAdapter(this, shareList);
		shareLV.setAdapter(adapter);
		shareLV.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long arg3) {
				switch (position) {
				case 0: {// 分享到QQ
					shareToQQ();
					break;
				}
				case 1: {// 分享到QQ空间
					shareToQzone();
					break;
				}
				case 2: {// 分享到新浪微博
					shareToSinaWeibo();
					break;
				}
				case 3: {// 分享到微信好友
					showToast("分享中···", true);
					shareToWeChatSession();
					break;
				}
				case 4: {// 分享到微信收藏
					showToast("分享中···", true);
					shareToWeChatFavorite();
					break;
				}
				case 5: {// 分享到微信朋友圈
					showToast("分享中···", true);
					shareToWeChatTimeline();
					break;
				}
				case 6: {// 更多
					share("", null);
					break;
				}
				default:
					break;
				}
			}
		});
	}

	/**
	 * 
	 * @Description: 初始化数据
	 */
	@SuppressLint("HandlerLeak")
	private void initData() {
		// 默认打开时候第一个选项为张开
		itemsLL.setVisibility(View.VISIBLE);
		itemsImg.setImageResource(R.drawable.arrow_up);
		llList = new ArrayList<LinearLayout>();
		llList.add(itemsLL);
		llList.add(otherLL);
		imgList = new ArrayList<ImageView>();
		imgList.add(itemsImg);
		imgList.add(otherImg);
		isOpenList = new ArrayList<Boolean>();
		isOpenList.add(true);
		isOpenList.add(false);
		picList = new ArrayList<ImageItem>();
		picFileList = new ArrayList<BmobFile>();
		if (from.contains("LOST")) {
			topTitleTV.setText(R.string.lost_find_lost);
		}
		if (from.contains("FIND")) {
			topTitleTV.setText(R.string.lost_find_find);
		}
		if (CommonConstant.FROM_LOSTFRAGMENT.equals(from)) {// check
			initLostData();
		}
		if (CommonConstant.FROM_FINDFRAGMENT.equals(from)) {// check
			initFindData();
		}
		topShareBtn.setVisibility(View.VISIBLE);
		// //////////////////////ShareSDK分享配置////////////////////////
		shareParams = new ShareParams();
		listener = new PlatformActionListener() {

			@Override
			public void onError(Platform arg0, int code, Throwable throwable) {
				LogcatUtils.e("分享失败： " + code + " " + throwable.getMessage());
				showToast("分享失败，请重试~ ", false);
			}

			@Override
			public void onComplete(Platform platform, int code,
					HashMap<String, Object> map) {
				showToast("分享到" + platform.getName() + "成功~", true);
			}

			@Override
			public void onCancel(Platform arg0, int code) {
				showToast("您已取消分享~", true);
			}
		};
		// //////////////////////友盟分享配置////////////////////////
		mShareController = UMServiceFactory
				.getUMSocialService("com.umeng.share");
		// 关闭自身的Toast
		mShareController.getConfig().closeToast();
		snsPostListener = new SnsPostListener() {

			@Override
			public void onStart() {
				showToast("分享中···", true);
			}

			@Override
			public void onComplete(SHARE_MEDIA media, int code,
					SocializeEntity entity) {
				switch (code) {
				case 200: {
					showToast("分享到" + media.name() + "成功~", true);
					break;
				}
				case 40000: {
					showToast("您已取消分享~", true);
					break;
				}
				default: {
					LogcatUtils.e("分享失败： " + code);
					showToast("分享失败 ，请重试~", false);
					break;
				}
				}
			}
		};
		shareHandler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				switch (msg.what) {
				case 12345: {
					showShareDialog();
					break;
				}
				}
			}
		};

	}

	/**
	 * 
	 * @Description: 初始化拾取数据
	 */
	private void initFindData() {
		FindThing findInfo = (FindThing) getIntent().getSerializableExtra(
				"findInfo");
		if (findInfo == null) {

		} else {
			titleET.setText(findInfo.getTitle());
			typeSp.setText(findInfo.getType());
			// setSpinnerItemSelectedByValue(typeSp, findInfo.getType());
			describeET.setText(findInfo.getDescribe());
			placeET.setText(findInfo.getPlace());
			timeET.setText(findInfo.getTime());
			phoneET.setText(findInfo.getPhone());
			picFileList = findInfo.getPicFileList();
			if (null == picFileList || 1 > picFileList.size()) {

			} else {
				for (BmobFile bmobFile : picFileList) {
					if (bmobFile != null) {
						ImageItem imageItem = new ImageItem();
						imageItem.setIsLocalPic(false);
						imageItem.setFileName(bmobFile.getFilename());
						imageItem.setImagePath(bmobFile
								.getFileUrl(LostAndFindActivity.this));
						picList.add(imageItem);
					}
				}
			}
			unEdit();
			if (null == picList || 1 > picList.size()) {// 若无图片信息隐藏图片信息该栏
				picGV.setVisibility(View.GONE);
			} else {
				unEditAdapter = new UnEditGridAdapter(// 若有图片信息显示图片信息该栏
						LostAndFindActivity.this, picList);
				picGV.setAdapter(unEditAdapter);
				unEditAdapter.notifyDataSetChanged();
			}
		}
	}

	/**
	 * 
	 * @Description: 初始化丢失数据
	 */
	private void initLostData() {
		LostThing lostInfo = (LostThing) getIntent().getSerializableExtra(
				"lostInfo");
		if (lostInfo == null) {

		} else {
			titleET.setText(lostInfo.getTitle());
			typeSp.setText(lostInfo.getType());
			describeET.setText(lostInfo.getDescribe());
			placeET.setText(lostInfo.getPlace());
			timeET.setText(lostInfo.getTime());
			phoneET.setText(lostInfo.getPhone());
			picFileList = lostInfo.getPicFileList();
			if (null == picFileList || 1 > picFileList.size()) {

			} else {
				for (BmobFile bmobFile : picFileList) {
					if (bmobFile != null) {
						ImageItem imageItem = new ImageItem();
						imageItem.setIsLocalPic(false);
						imageItem.setFileName(bmobFile.getFilename());
						imageItem.setImagePath(bmobFile
								.getFileUrl(LostAndFindActivity.this));
						picList.add(imageItem);
					}
				}
			}
			unEdit();
			if (null == picList || 1 > picList.size()) {// 若无图片信息隐藏图片信息该栏
				picGV.setVisibility(View.GONE);
			} else {
				unEditAdapter = new UnEditGridAdapter(// 若有图片信息显示图片信息该栏
						LostAndFindActivity.this, picList);
				picGV.setAdapter(unEditAdapter);
				unEditAdapter.notifyDataSetChanged();
			}
		}
	}

	/**
	 * 
	 * @Description: 瓷砖特效
	 */
	private void initMaterialRipple() {
		// 设置Padding
		titleET.setPaddings(DensityUtils.sp2px(this, 32), 0, 0, 0);
		typeSp.setPaddings(DensityUtils.sp2px(this, 32), 0, 0, 0);
		describeET.setPaddings(DensityUtils.sp2px(this, 32), 0, 0, 0);
		placeET.setPaddings(DensityUtils.sp2px(this, 32), 0, 0, 0);
		timeET.setPaddings(DensityUtils.sp2px(this, 32), 0, 0, 0);
		phoneET.setPaddings(DensityUtils.sp2px(this, 32), 0, 0, 0);
		// 设置验证信息
		phoneET.addValidator(new METValidator("请输入正确的联系号码格式~") {

			@Override
			public boolean isValid(@NonNull CharSequence text, boolean isEmpty) {
				String number = text.toString();
				if ("".equals(number) || VerifyUtils.checkPhone(number)) {
					return true;
				}
				return false;
			}
		});

		List<View> views = new ArrayList<View>();
		views.add(itemsRL);
		views.add(otherRL);
		for (View view : views) {
			// 动态特效
			MaterialRippleLayout
					.on(view)
					.rippleColor(
							Color.parseColor(CommonConstant.RIPPLE_COLOR_LITHT))
					.rippleAlpha(CommonConstant.RIPPLE_ALPHA).rippleHover(true)
					.create();
		}

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.top_back_btn: {// 返回按钮
			finish();
			break;
		}
		case R.id.top_share_btn: {// 分享按钮
			for (LinearLayout layout : llList) {
				layout.setVisibility(View.VISIBLE);
			}
			for (ImageView image : imgList) {
				image.setImageResource(R.drawable.arrow_up);
			}
			for (Boolean isOpen : isOpenList) {
				if (!isOpen) {
					isOpen = true;
				}
			}
			new Thread(new Runnable() {

				@Override
				public void run() {
					try {
						// 延时等待物品信息和其他信息都展开
						Thread.sleep(800);
						Message msg = new Message();
						msg.what = 12345;
						shareHandler.sendMessage(msg);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}).start();
			break;
		}
		default:
			break;
		}
	}

	String title = "";
	String type = "";
	String describe = "";
	String place = "";
	String time = "";
	String phone = "";

	/**
	 * @Description:控件设置不可编辑
	 */
	private void unEdit() {
		titleET.setEnabled(false);
		typeSp.setEnabled(false);
		typeSp.setFocusable(false);
		typeSp.setFocusableInTouchMode(false);
		describeET.setSingleLineEllipsis(false);
		describeET.setShowClearButton(false);
		describeET.setEnabled(false);
		placeET.setEnabled(false);
		timeET.setEnabled(false);
		phoneET.setEnabled(false);
	}

	/**
	 * @Description: 按键监听更改布局
	 */
	public void newLostOrFindClick(View v) {
		for (LinearLayout ll : llList) {
			ll.setVisibility(View.GONE);
		}
		for (ImageView img : imgList) {
			img.setImageResource(R.drawable.arrow_down);
		}
		switch (v.getId()) {
		case R.id.lost_find_items_title_rl: {// 物品信息
			if (isOpenList.get(0)) {
				isOpenList.set(0, false);
			} else {
				llList.get(0).setVisibility(View.VISIBLE);
				for (int i = 0; i < isOpenList.size(); i++) {
					isOpenList.set(i, false);
				}
				isOpenList.set(0, true);
				imgList.get(0).setImageResource(R.drawable.arrow_up);
			}
			break;
		}
		case R.id.lost_find_other_title_rl: {// 其他信息
			if (isOpenList.get(1)) {
				isOpenList.set(1, false);
			} else {
				llList.get(1).setVisibility(View.VISIBLE);
				for (int i = 0; i < isOpenList.size(); i++) {
					isOpenList.set(i, false);
				}
				isOpenList.set(1, true);
				imgList.get(1).setImageResource(R.drawable.arrow_up);
			}
			break;
		}
		}
	}

	/**
	 * @Description: 图片列表按键监听
	 */
	@Override
	public void onItemClick(AdapterView<?> arg0, View view, int position,
			long arg3) {
		if (position == picList.size()) {

		} else {
			String[] imagePaths = new String[picList.size()];
			for (int i = 0; i < picList.size(); i++) {
				if (picList.get(i).getIsLocalPic()) {
					imagePaths[i] = "file://" + picList.get(i).getImagePath();
				} else {
					imagePaths[i] = picList.get(i).getImagePath();
				}
			}
			loadLocalImage(position, imagePaths);
		}
	}

	/**
	 * 
	 * @Description: 加载本地的图片
	 * @param position
	 * @param imagePath
	 */
	private void loadLocalImage(int position, String[] imagePaths) {
		Intent intent = new Intent(LostAndFindActivity.this,
				ImagePagerActivity.class);
		intent.putExtra(ImagePagerActivity.IMAGE_URLS, imagePaths);
		intent.putExtra(ImagePagerActivity.IMAGE_INDEX, position);
		startActivity(intent);
	}

	// /////////////////////////分享////////////////////////////////
	/**
	 * 
	 * @Description: 弹出推荐分享框
	 */
	@SuppressLint("NewApi")
	private void showShareDialog() {
		// 获取图片
		Bitmap topBitmap = ScreenUtils.getViewBitmap(topLayout);
		Bitmap itemsBitmap = ScreenUtils.getViewBitmap(itemLayout);
		Bitmap otherBitmap = ScreenUtils.getViewBitmap(otherLayout);
		if (null == topBitmap || null == itemsBitmap || null == otherBitmap) {

		} else {
			List<Bitmap> bitmaps = new ArrayList<Bitmap>();
			bitmaps.add(topBitmap);
			bitmaps.add(itemsBitmap);
			bitmaps.add(otherBitmap);
			// 图片拼接
			bitmap = ScreenUtils.addManyBitmap(bitmaps);
			if (null != bitmap) {
				shareImagePath = FileUtils.getImagePath();
				if (null != shareImagePath) {
					FileUtils.saveBitmap(bitmap, shareImagePath);
					if (FileUtils.isFilePathExist(shareImagePath)) {
						shareParams.setImagePath(shareImagePath);
					}
				}

			}
		}
		theDialog.show();
		theDialog.setContentView(shareView);
		Window window = theDialog.getWindow();
		window.setGravity(Gravity.BOTTOM);
		window.getDecorView().setPadding(0, 0, 0, 0);
		WindowManager.LayoutParams lp = window.getAttributes();
		lp.width = WindowManager.LayoutParams.MATCH_PARENT;
		lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
		window.setAttributes(lp);

	}

	/**
	 * 
	 * @Description: 分享到QQ好友
	 */
	private void shareToQQ() {
		// ShareSDK图文分享 纯图片分享无法回调
		// shareParams.setText(CommonConstant.SHARE_CONTENT);
		// shareParams.setTitle(CommonConstant.SHARE_TITLE);
		// shareParams.setTitleUrl(CommonConstant.SHARE_TARGET_URL);
		// Platform qqPlatform = ShareSDK.getPlatform(QQ.NAME);
		// qqPlatform.setPlatformActionListener(listener);
		// qqPlatform.share(shareParams);
		// 使用友盟分享 QQ图文分享(QQ不支持无客户端纯图片分享)
		if (AppUtils.isInstallApplication("com.tencent.mobileqq")) {
			mShareController.setShareContent(null);
			if (null != bitmap) {
				mShareController.setShareImage(new UMImage(this, bitmap));
			}
			mShareController.postShare(this, SHARE_MEDIA.QQ, snsPostListener);
		} else {
			showToast("请先安装最新版QQ~", false);
		}
	}

	/**
	 * 
	 * @Description: 分享到空间
	 */
	private void shareToQzone() {
		// 使用ShareSDK分享 图片需要先上传服务器速度慢 空间不支持纯图片
		// shareParams.setTitle(CommonConstant.SHARE_TITLE);
		// shareParams.setTitleUrl(CommonConstant.SHARE_TARGET_URL);
		// shareParams.setText(CommonConstant.SHARE_CONTENT);
		// shareParams.setSite("Lifeassistants");
		// shareParams.setSiteUrl(CommonConstant.SHARE_TARGET_URL);
		// Platform qZonePlatform = ShareSDK.getPlatform(QZone.NAME);
		// // 设置false表示使用SSO授权方式
		// qZonePlatform.SSOSetting(false);
		// qZonePlatform.setPlatformActionListener(listener);
		// qZonePlatform.share(shareParams);
		// 使用友盟分享 QQ空间图文分享
		if (AppUtils.isInstallApplication("com.qzone")
				|| AppUtils.isInstallApplication("com.tencent.mobileqq")) {
			mShareController.setShareContent(CommonConstant.SHARE_CONTENT);
			if (null != bitmap) {
				mShareController.setShareImage(new UMImage(this, bitmap));
			}
			mShareController
					.postShare(this, SHARE_MEDIA.QZONE, snsPostListener);
		} else {
			showToast("请先安装最新版QQ空间或QQ~", false);
		}
	}

	/**
	 * 
	 * @Description: 分享到新浪微博
	 */
	private void shareToSinaWeibo() {
		// 新浪微博图文分享
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("Id", "1");// 自定义字段，整型，用于您项目中对此平台的识别符
		hashMap.put("SortId", "1");// "此平台在您分享列表中的位置，整型，数值越大越靠后"
		hashMap.put("AppKey", CommonConstant.SINA_APP_ID);// 填写您在新浪微博上注册到的AppKey
		hashMap.put("AppSecret", CommonConstant.SINA_APP_SECRET);// 填写您在新浪微博上注册到的AppSeret
		hashMap.put("RedirectUrl", CommonConstant.SINA_REDIRECT_URL);// 填写您在新浪微博上注册的RedirectUrl
		if (AppUtils.isInstallApplication("com.sina.weibo")) {
			hashMap.put("ShareByAppClient", "true");// 使用客户端进行分享
		} else {
			hashMap.put("ShareByAppClient", "false");// 不使用客户端进行分享
		}
		hashMap.put("Enable", "true");// 布尔值，标记此平台是否有效
		ShareSDK.setPlatformDevInfo(SinaWeibo.NAME, hashMap);
		if (AppUtils.isInstallApplication("com.sina.weibo")) {
			// 调用新浪微博客户端授权分享
			shareParams.setText(CommonConstant.SHARE_CONTENT);
			shareParams.setUrl(CommonConstant.SHARE_TARGET_URL);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			shareParams.setTitleUrl(CommonConstant.SHARE_TARGET_URL);
			shareParams.setShareType(Platform.SHARE_WEBPAGE);
			Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME);
			// 设置false表示使用SSO授权方式
			weibo.SSOSetting(false);
			// 设置分享事件回调
			weibo.setPlatformActionListener(listener);
			weibo.share(shareParams);
		} else {
			// 调用网页授权分享
			OnekeyShare oks = new OnekeyShare();
			oks.setPlatform(SinaWeibo.NAME);
			// 显示编辑页面
			oks.setSilent(false);
			// 显示为Dialog
			oks.setDialogMode();
			oks.setText(CommonConstant.SHARE_CONTENT + "下载地址"
					+ CommonConstant.SHARE_TARGET_URL + " ");
			if (null != shareImagePath) {
				oks.setImagePath(shareImagePath);
			}
			oks.setCallback(listener);
			oks.show(this);
		}
	}

	/**
	 * 
	 * @Description: 分享到微信好友
	 */
	private void shareToWeChatSession() {
		if (AppUtils.isInstallApplication("com.tencent.mm")) {
			// 纯图片分享
			shareParams.setText(null);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			// 分享类型 图片
			shareParams.setShareType(Platform.SHARE_IMAGE);
			Platform wxPlatform = ShareSDK.getPlatform(Wechat.NAME);
			wxPlatform.setPlatformActionListener(listener);
			wxPlatform.share(shareParams);
		} else {
			showToast("请先安装最新版微信~", false);
		}

	}

	/**
	 * 
	 * @Description: 分享到微信朋友圈
	 */
	private void shareToWeChatTimeline() {
		if (AppUtils.isInstallApplication("com.tencent.mm")) {
			// 纯图片分享
			shareParams.setText(null);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			// 分享类型 图片
			shareParams.setShareType(Platform.SHARE_IMAGE);
			Platform wxTimeLinePlatform = ShareSDK
					.getPlatform(WechatMoments.NAME);
			wxTimeLinePlatform.setPlatformActionListener(listener);
			wxTimeLinePlatform.share(shareParams);
		} else {
			showToast("请先安装最新版微信~", false);
		}

	}

	/**
	 * 
	 * @Description: 分享到微信收藏
	 */
	private void shareToWeChatFavorite() {
		if (AppUtils.isInstallApplication("com.tencent.mm")) {
			// 纯图片分享
			shareParams.setText(null);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			// 分享类型 图片
			shareParams.setShareType(Platform.SHARE_IMAGE);
			Platform wxFavoritePlatform = ShareSDK
					.getPlatform(WechatFavorite.NAME);
			wxFavoritePlatform.setPlatformActionListener(listener);
			wxFavoritePlatform.share(shareParams);
		} else {
			showToast("请先安装最新版微信~", false);
		}

	}

	/**
	 * 
	 * @Description: 分享更多
	 */
	private void share(String packages, Uri uri) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		if (uri != null) {
			intent.setType("image/*");
			intent.putExtra(Intent.EXTRA_STREAM, uri);
		} else {
			intent.setType("text/plain");
		}
		intent.putExtra(Intent.EXTRA_SUBJECT, "分享到");
		intent.putExtra(Intent.EXTRA_TEXT, CommonConstant.SHARE_CONTENT
				+ "下载地址" + CommonConstant.SHARE_TARGET_URL);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		if (!TextUtils.isEmpty(packages))
			intent.setPackage(packages);
		startActivity(Intent.createChooser(intent, "分享到"));
	}

	/**
	 * 
	 * @Description: Toast显示信息
	 */
	private void showToast(String message, Boolean isInfo) {
		if (isInfo) {
			ToastUtils.showInfoToast(this, message, R.id.lost_find_content_ll);
		} else {
			ToastUtils.showAlertToast(this, message, R.id.lost_find_content_ll);
		}

	}
}
